home *** CD-ROM | disk | FTP | other *** search
- /*
-
- $HISTORY:
- 26 Apr 1994, 1.06: The fact that Dietmar included the possibility to detect
- whitespaces confused me a lot. ;-) Everything appeared
- to be broken, but in fact it was not. I went over the
- code once more to detect minor changes and tried to
- avoid the whitespaces-problem for any configuration.<LL>
- Just leave :;,. and () out of your GUI-config.
- 31 Dec 1993, 1.05: The code aimed at toggling word-wrap mode off/on has
- been moved from the style_block routine to the main
- routine. No more undesired word-wrap in `word'
- styling mode. Fix another potential bug (an end was
- missing at the end of the else part of the main routine
- this went unseen 'cause the script exited right at the
- missing end position.
-
- 23 Dec 1993, 1.04: changes to fix a bug which occured when style4Spot was
- called while the cursor was in a `word' composed of
- blanks and no block was selected (ie in word mode),
- and another one wich occured when `styling' a word
- (while in word mode) which was the last of the line.
- There's now a new procedure called: "word_style".
- It's worth (funny?) noticing that we corrected bugs
- wich are the exact equivalent at word level of the
- bugs we fixed previously which occured at a `line level'
- (cfr version 1.03). Which should draw our attention on
- dealing with `special case' (e.g. boundery-case). <TM>
-
- 13 Dec 1993, 1.03: fixed a bug which occured when the `styled' line was the
- last of the file. Minor change to enable handling of
- blocks wich include `empty' lines :).
- Added mome comments :). <TM>
-
- 27 Nov 1993, 1.02: fixed (?) a bug related with the wordwrap mode.
- Minor code cleanup <TM>.
-
- 24 Oct 1993, 1.01: fixed some bugs, minor (?)changes and cleaned
- up the code <TM>.
-
- */
-
- /* ©1993 Tattoo Mabonzo/Lieven Lema. TEXTSTYLES FOR SPOT! */
- /* INCLUDE <standard_disclaimer.h> ;-) */
-
- /* Thanks to Phillipe Van Der Gucht for some nice suggestions. */
-
- /* HOW TO USE IT? */
- /* ------------- */
-
- /* Just put the cursor on the word (or right next to the word ) you */
- /* want to apply textstyle to, or select a block and invoke the */
- /* script. It's that easy :-) */
- /* You can of course bind the script to a key or a menu in GOLDED. */
- /* This is netware, if you like it, send us a netmail. */
- /* Please also report any bugs, qwirks... you might discover. */
- /* Suggestion on improvements welcome too! */
- /* Tattoo Mabonzo 2:291/715.8 Lema 2:292/603.11 */
-
-
- OPTIONS RESULTS /* enable return codes */
-
- if (LEFT(ADDRESS(), 6) ~= "GOLDED") then /* not started by GoldEd ? */
- address 'GOLDED.1'
-
- 'LOCK CURRENT' /* lock GUI, gain access */
- OPTIONS FAILAT 6 /* ignore warnings */
- SIGNAL ON SYNTAX /* ensure clean exit */
-
-
- /* ------------------------- INSERT YOUR CODE HERE: ------------------ */
-
-
- 'REQUEST STATUS "/// applying text style..."'
- 'REQUEST TITLE="Text Styles" BODY="Please choose a textstyle for word or block application." BUTTON="I|B|U|IB|IU|BU|IBU|CANCEL"'
-
- number = RESULT /* get the user choice (a textstyle or `cancel' */
-
- if number = 0 then do /* user selected cancel */
- 'UNLOCK' /* clean exit */
- exit
- end
-
- else do /* user actually selected a textstyle */
-
- 'QUERY SPC VAR SPACE' /* remember white space settings */
- 'GUI SPC=32' /* set word separator */
-
- 'QUERY WRAP VAR WORDWRAP' /* let's store current word wrap mode */
- 'LAYOUT WRAP=FALSE' /* we disable wordwrap (ie REFORMAT mode is also disabled) in any case */
- call head_tail_symbols(number) /* let's get the appropriate text style symbols */
- 'QUERY MARKED' /* Do we deal with a block or a single word ? */
-
- if (RESULT = 'TRUE') then do /* we've got a block... */
- 'PING SLOT 0' /* let's remember current cursor position */
- call block_style() /* There exists a marked block, so let's apply textstyle to it */
- 'PONG SLOT 0' /* we reset cursor position */
- end
- else do /* No block marked, we apply textstyle to a single word */
- 'PING SLOT 0' /* let's remember current cursor position */
- call word_style()
- 'PONG SLOT 0' /* we reset cursor position */
- end
-
- 'LAYOUT WRAP=' || WORDWRAP /* we restore the original wordwrap mode*/
-
- 'FIX VAR=SPACE' /* might contain '*' */
- 'GUI SPC="' || SPACE || '"' /* we restore white space settings */
-
- end
-
- 'UNLOCK' /* clean exit */
- exit
-
- /*--------------------------------------------------------------------*/
-
- head_tail_symbols:
-
- /* Initializes a compound variable with the text styles symbols */
- /* takes a number as it's arguments and returns (as a side effect */
- /* the so called `head' and `tail' text style symbols */
-
- parse arg S /* we get the number corresponding to the */
- /* the user chose. */
- styles.1.head = "/"
- styles.1.tail = "/"
- styles.2.head = "*"
- styles.2.tail = "*"
- styles.3.head = "_"
- styles.3.tail = "_"
- styles.4.head = "/*"
- styles.4.tail = "*/"
- styles.5.head = "/_"
- styles.5.tail = "_/"
- styles.6.head = "*_"
- styles.6.tail = "_*"
- styles.7.head = "/*_"
- styles.7.tail = "_*/"
-
- head_symbol = styles.S.head /* we initialize the textstyle symbol variables */
- tail_symbol = styles.S.tail /* with the appropriate symbols */
-
- return
-
- /*--------------------------------------------------------------------*/
-
- block_style:
-
- /* This routine applies the chosen text style to the selected block of text */
- /* It actually only manages the `block' size of the thing. The actual styling */
- /* is taken care of by the apply_style routine. */
-
- 'QUERY BLAST VAR BLAST' /* let's query for and store important parameters */
-
- 'GOTO BFIRST'
- 'QUERY LINE VAR LINE' /* what's the block first line number? */
- OLDLINE = -1 /* we initialize a variable which will */
- /* remember the number of the line we've */
- /* just treated. It'll help us make sure */
- /* we don't treat the same line more than */
- /* once, which would occur when line */
- /* being treated is the last one in the file */
-
- do while ((LINE <= BLAST) & (OLDLINE ~= LINE)) /* while we still have a line to treat... */
- charcode = first_word() /* which has NOT yet been treated ... */
-
- do while (charcode ~= _EOL) /* while we still have a word to treat...*/
- charcode = apply_style()
- end
-
- if EmptyLine then do /* in case of a empty line ... */
- 'FIRST'
- 'RIGHT' /* we go to the BOL ... */
- 'DELETE EOL' /* and delete everything passed to it */
- end
- else do /* our line was NOT empty ... */
- 'PREVEND' /* from our '_EOL' char, back to end of the last word */
- 'RIGHT' /* We're now just right next to the last word... */
- 'DELETE EOL' /* ...We can (should!) delete anything we added... */
- end
-
- OLDLINE = LINE /* we store the line number of the line we've just */
- 'DOWN' /* treated and step down to the next line ... */
- 'QUERY LINE VAR LINE' /* ... and get the new line number */
- end
-
-
- return
-
- /*--------------------------------------------------------------------*/
-
- first_word:
-
- /* This procedure first sets a special marker for easy locating of the EOL */
- /* and returns the first `printable' (cfr code) of the the sentence or the */
- /* special marker code if the line does not include any `printable' character */
- /* As a side effect it also sets a boolean indicator `EmptyLIne' to `1' in */
- /* in the later case (else EmptyLine = 0)*/
-
- _EOL = 10 /* we define a End Of Line `constant' */
- EmptyLine = 0 /* a priori we consider the line NOT being empty */
- 'GOTO EOL' /* we're after the last char of the last word on the sentence */
- 'RIGHT' /* we insert a blank... */
- 'CODE SET=' || _EOL /* ... and set our '_EOL' marker */
-
- /* *** Now the last *WORD* of our sentence is actually */
- /* *** a *ONE-character* word which ASCII value equals */
- /* *** that of our '_EOL' `constant' */
-
-
-
- 'FIRST' /* to 'BOL'... */
- 'QUERY CODE VAR CODE'
- /* let's find the first printable char (or the '_EOL')... */
-
- do while (((CODE < 33) ^ ((CODE > 127) & (CODE < 160))) & (CODE ~= _EOL))
- 'RIGHT'
- 'QUERY CODE VAR CODE'
- end
-
- if CODE = _EOL then /* our line doesn't include any `printable' chararcter */
- EmptyLine = 1
-
- return CODE /* ... we return the first `printable' char (or _EOL) */
- /* as the result of the function call */
-
- /*--------------------------------------------------------------------*/
-
- word_style:
-
- /* The purpose of this routine is to handle some special case of one-word style */
- /* application. Namely when the single word we want to apply style to is the last */
- /* in the sentence. In that case the delete word function will also delete the */
- /* linefeed char and thus cause the next sentence to jump backward to the end of */
- /* the current line. Which we want to avoid. It also handle the case where the */
- /* script is called while the cursor in the middle of `blanks' and there's no */
- /* selected. This should contribute to making this script a little bit more */
- /* `idiot-proof' ;-)... */
-
- 'QUERY WORD VAR CUR_WORD' /* let's get the word the cursor on or next to */
-
- CW_LEN = wordlength(CUR_WORD,1) /* what's the length of that word? (if any...) */
-
- if (CW_LEN ~= 0) then do
-
- 'PING SLOT=1' /* we store current cursor position */
-
- _EOL = 10 /* we define a End Of Line `constant' */
- 'GOTO EOL' /* we're on blank after the last char of the last word on the sentence */
- 'RIGHT' /* we insert a blank... */
- 'CODE SET=' || _EOL /* ... and set our '_EOL' marker */
-
- 'PONG SLOT=1' /* we restore cursor position */
-
- call apply_style()
-
- 'GOTO EOL'
- 'LEFT' /* we 're now 'on' our EOL char...*/
-
- 'PREVEND' /* ... */
- 'RIGHT'
- 'DELETE EOL' /* we delete what we've added */
- end
-
- return 1
-
- /*--------------------------------------------------------------------*/
-
- apply_style:
-
- /* This is the actual `styling' routine. It's word oriented. It applies a text */
- /* style to the word the cursor is on or right next to. */
- /* Returns the first character ASCII code of the next word in the line */
-
- 'QUERY WORD VAR CURWORD' /* let's get the word the cursor on or next to */
-
- CW_LEN = length(CURWORD) /* what's the length the current word? */
-
- LWC = C2D(substr(CURWORD,CW_LEN)) /* we store our current word last char ASCII code */
-
- /* is last char one of <;:,.()> ? */
- if ((LWC=058)^(LWC=059)^(LWC=044)^(LWC=046)^(LWC=047)^(LWC=061)) then
-
- /* thus the textstyle symbol should come before the punctuation sign */
-
- CURBWORD = head_symbol || substr(CURWORD,1,(CW_LEN - 1)) || tail_symbol || D2C(LWC)
-
- else
-
- CURBWORD = head_symbol || CURWORD || tail_symbol /* ditto */
-
- 'DELETE WORD' /* we now can safely erase the current word... */
-
- 'FIX VAR=CURBWORD' /* consider '*' & '"' */
-
- 'TEXT T="' || CURBWORD || ' "' /* post-insert the `styled' form */
-
- 'QUERY CODE VAR CODE' /* we now should be on the first char of the word */
- /* next to the one we just replaced. Let's get */
- /* its ASCII code...*/
-
- return CODE /* ...which we return as our function result */
-
-
- /* --- ------- ------ ------------ */
- /*END OF YOUR CODE*/
- /*----- ---- --- */
- /*------ -- --- */
-
- SYNTAX:
-
- SAY "Sorry, error line" SIGL ":" ERRORTEXT(RC) ":-("
-
- 'UNLOCK'
- EXIT
-
-